<template>
  <section class="login-bg">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" label-width="0px" class="login-container">
      <h3 class="title">完善资料 - 绑定已有账号</h3>
      <el-form-item>
        <el-input type="text" :value="$route.query.driver + '账号 ' + $route.query.nickname" disabled></el-input>
      </el-form-item>
      <el-form-item prop="account">
        <el-input type="text" v-model="ruleForm.account" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-checkbox v-model="checked" disabled class="remember">记住密码</el-checkbox>
      <el-form-item>
        <el-button type="primary" 
          style="width:100%;" @click.native.prevent="handleSubmit" 
          :loading="logining">绑定并登录
        </el-button>
        <p class="info">绑定账号后，下次可直接使用第三方账号登陆</p>
      </el-form-item>
    </el-form>
    <div class="account-about ">
      <span>Copyright&nbsp;&nbsp;©&nbsp;2017&nbsp;yuethink.com&nbsp;&nbsp;</span>
      <a href="http://www.yuethink.com" target="_blank">技术支持-贵州越想互联科技有限公司</a>
      <a href="http://www.miitbeian.gov.cn/" target="_blank">黔ICP备17005668号-1</a>
      <span>Version 1.0</span>
    </div>
  </section>
</template>
<script>
  export default {
    data () {
      return {
        logining: false,
        ruleForm: {
          account: '',
          password: '',
          open_id: '',
          driver: ''
        },
        rules: {
          account: [
            {required: true, message: '请输入账号', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请输入密码', trigger: 'blur'}
          ]
        },
        checked: false
      }
    },
    mounted () {
      this.ruleForm.open_id = this.$route.query.open_id
      this.ruleForm.driver = this.$route.query.driver
    },
    methods: {
      handleSubmit (ev) {
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            this.logining = true
            this.$http.post('/socialite/binding', this.ruleForm).then(response => {
              this.logining = false
              this.$router.push('/login?access_token=' + response.data.access_token)
            }).catch(() => {
              this.logining = false
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .login-bg {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #ccc;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: url(./images/bg.jpg) center center / cover no-repeat fixed;
    &:before {
      content: '';
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      background: rgba(0, 0, 0, .5);
    }
    .login-container {
      z-index: 100;
      -webkit-border-radius: 5px;
      border-radius: 5px;
      -moz-border-radius: 5px;
      background-clip: padding-box;
      width: 350px;
      padding: 35px 35px 15px 35px;
      background: #fff;
      border: 1px solid #eaeaea;
      box-shadow: 0 0 25px #cac6c6;
      .title {
        margin: 0 auto 40px auto;
        text-align: center;
        color: #505458;
      }
      .remember {
        margin: 0 0 35px 0;
      }
      .info {
        color: #999;
        text-align: center;
      }
    }
    .account-about {
      position: absolute;
      font-size: 14px;
      left: 30px;
      bottom: 25px;
      a, span {
        color: #666;
        text-decoration: none;
        margin-right: 15px;
      }
    }
  }
</style>